package org.wzy.xmlg_backend.service.impl;

import org.wzy.xmlg_backend.mapper.StudentMapper;
import org.wzy.xmlg_backend.service.IStudentStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class StudentStatisticsServiceImpl implements IStudentStatisticsService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Map<String, Long> countByGender() {
        return studentMapper.countByGender()
                .stream()
                .collect(Collectors.toMap(
                        map -> (String) map.get("gender"),
                        // 修复Long类型转换问题
                        map -> ((Number) map.get("count")).longValue()
                ));
    }

    @Override
    public List<Map<String, Object>> countByClass() {
        return studentMapper.countByClass();
    }

    @Override
    public Map<String, Long> countByStatus() {
        return studentMapper.countByStatus()
                .stream()
                .collect(Collectors.toMap(
                        map -> (String) map.get("status"),
                        // 修复Long类型转换问题
                        map -> ((Number) map.get("count")).longValue()
                ));
    }

    @Override
    public List<Map<String, Object>> countByLocation() {
        return studentMapper.countByLocation();
    }
}